#!/bin/python
# -*- coding: utf-8 -*-
import gdata.docs.data
import gdata.docs.client

class EricClient(object):
    def __init__(self):
        self.client = gdata.docs.client.DocsClient(source='EricClient-v1')
        self.client.ssl = True  # Force all API requests through HTTPS
        self.client.http_client.debug = False  
        self.client.ClientLogin('xu.mathena@gmail.com', 'Some Pa$$Word!', self.client.source);


    def upload(self, name, f):
        u ='/feeds/default/private/full?title=' + name + '&title-exact=true&max-results=5'
        feed = self.client.GetDocList(uri = u)
        target = feed.entry[0]
        ms = gdata.data.MediaSource(file_path=f, content_type='text/html')
        updated_entry = self.client.Update(target, media_source=ms)

if __name__ == "__main__":
    c = EricClient()
    c.upload("序言", "html/preface.html")